package com.zscbw.test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Method2 {
	public int add(int a, int b) {
		return a + b;
	}
	public static void main(String[] args) {
		try {
			Class<?> cls = Class.forName("com.zscbw.test.Method2");
			Class[] parTypes = new Class[2];
			parTypes[0] = Integer.TYPE;
			parTypes[1] = Integer.TYPE;

			Method method = cls.getMethod("add", parTypes);

			Object[] argList = new Object[2];
			argList[0] = new Integer(37);
			argList[1] = new Integer(43);

			Object regObj = method.invoke(cls.newInstance(), argList);
			Integer retVal = (Integer) regObj;
			System.out.println(retVal.intValue());
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		} catch (SecurityException e) {
			throw new RuntimeException(e);
		} catch (NoSuchMethodException e) {
			throw new RuntimeException(e);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
